﻿using System;
using System.Runtime.InteropServices;

namespace ObjectPool
{
    [StructLayout(LayoutKind.Auto)]
    public struct ObjectInfo
    {
        /// <summary>
        /// 对象名称
        /// </summary>
        private readonly string m_Name;
        /// <summary>
        /// 对象是否锁定
        /// </summary>
        private readonly bool m_Locked;
        /// <summary>
        /// 对象自定义释放检查标记
        /// </summary>
        private readonly bool m_CustomCanReleaseFlag;
        /// <summary>
        /// 对象优先级
        /// </summary>
        private readonly int m_Priority;
        /// <summary>
        /// 最后使用时间
        /// </summary>
        private readonly DateTime m_LastUseTime;
        /// <summary>
        /// 对象生成次数
        /// </summary>
        private readonly int m_SpawnCount;


        public ObjectInfo(string name, bool locked, bool customCanReleaseFlag, int priority, DateTime lastUseTime,
            int spawnCount)
        {
            m_Name = name;
            m_Locked = locked;
            m_CustomCanReleaseFlag = customCanReleaseFlag;
            m_Priority = priority;
            m_LastUseTime = lastUseTime;
            m_SpawnCount = spawnCount;
        }
        
        /// <summary>
        /// 对象名称
        /// </summary>
        public string Name
        {
            get { return m_Name; }
        }
        
        /// <summary>
        /// 获取对象是否被加锁。
        /// </summary>
        public bool Locked
        {
            get
            {
                return m_Locked;
            }
        }
        
        /// <summary>
        /// 获取对象自定义释放检查标记
        /// </summary>
        public bool CustomCanReleaseFlag
        {
            get
            {
                return m_CustomCanReleaseFlag;
            }
        }
        
        /// <summary>
        /// 获取对象的优先级。
        /// </summary>
        public int Priority
        {
            get
            {
                return m_Priority;
            }
        }

        /// <summary>
        /// 获取对象上次使用时间。
        /// </summary>
        public DateTime LastUseTime
        {
            get
            {
                return m_LastUseTime;
            }
        }

        /// <summary>
        /// 获取对象是否正在使用。
        /// </summary>
        public bool IsInUse
        {
            get
            {
                return m_SpawnCount > 0;
            }
        }

        /// <summary>
        /// 获取对象的获取计数。
        /// </summary>
        public int SpawnCount
        {
            get
            {
                return m_SpawnCount;
            }
        }

    }
}